// https://leetcode.cn/problems/longest-consecutive-sequence/
// Created by ade on 2022/7/22.
//
#include <iostream>
#include <vector>
#include <algorithm>


using namespace std;

class Solution {
public:
    int longestConsecutive(vector<int> &nums) {
        int len = nums.size();
        if (len <= 1) return len;
        sort(nums.begin(), nums.end());
        int maxS = 1;
        for (int i = 0; i < len - 1; i++) {
            int tmp = 1;
            while (i < len - 1 && nums[i + 1] - nums[i] <= 1) {
                if (nums[i + 1] - nums[i] == 1)
                    tmp++;
                i++;
            }
            maxS = max(tmp, maxS);
            if (maxS > len - 1 - i) break;
        }
        return maxS;
    }
};

int main() {
    Solution so;
    vector<int> intervals = {0, 3, 7, 2, 5, 8, 4, 6, 0, 1};
    int a = so.longestConsecutive(intervals);
    cout << a << endl;
    return 0;
}
